package com.xhj.bigfactory.bigFactory.Collection;

import java.util.*;
/**
 * -
 *
 * @author 周沫 @Date 2021-07-25 @Time 14:55
 */
public class ArrayListDemo {
  public static void main(String[] args) {
    //  	List<String> list= new CopyOnWriteArrayList<>();
    //    List<String> list = Collections.synchronizedList(new ArrayList<>());// - - - - - - -"输出有误"
    List<String> list = new ArrayList<>(); // - - - - - - -"并发修改异常"
    //    List<String> list = Arrays.asList("a","b","c");// - - - - - - -"操作异常"
    list.add("a");
    list.add("b");
    list.add("c");
    list.forEach(System.out::print);
    System.out.println();
    for (int i = 0; i < 12; i++) {
      new Thread(
              () -> {
                System.out.println(Thread.currentThread().getName() + " come in...");
                list.add(String.valueOf(new Random().nextInt(10)));
                System.out.println("list.size(): " + list.size());
              },
              "t" + i)
          .start();
    }
    HashMap<Integer, String> map = new HashMap<>();
  }
}
